import 'package:flutter/material.dart';

class BaseCardComponent extends StatelessWidget {

  /// 组件
  final Widget child;

  /// 内边距
  final EdgeInsetsGeometry padding;

  /// 外边距
  final EdgeInsetsGeometry margin;

  /// 点击事件
  final Function onTap;

  /// 长按事件
  final Function onLongPress;

  /// 背景颜色
  final Color backgroundColor;

  /// 卡片的圆角
  final double circular;

  BaseCardComponent({
    Key key,
    @required this.child,
    this.onTap,
    this.onLongPress,
    this.circular = 10,
    this.margin = const EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 0),
    this.padding = const EdgeInsets.all( 12.0 ),
    this.backgroundColor,
  }) : super(key: key);

  BaseCardComponent.yjb({
    Key key,
    @required this.child,
    this.onTap,
    this.onLongPress,
    this.circular = 8,
    this.margin = const EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0),
    this.padding = const EdgeInsets.all( 10.0 ),
    this.backgroundColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 0,
      margin: margin,
      color: backgroundColor,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(this.circular))),
      child: _buildInkWellWidget(),
    );
  }

  Widget _buildInkWellWidget() {
    return InkWell(
      borderRadius: BorderRadius.all(Radius.circular(this.circular)),
      onTap: this.onTap,
      onLongPress: this.onLongPress,
      child: Container(
        padding: this.padding,
        child: this.child,
      ),
    );
  }

}
